
$(document).ready(function(e) {

    $('#start').blur(function(){
        let start= $('#start').val();
        let end = $('#end').val();
        if(start=="" || end==""){
            
            $('#tips').text("查询地址不能为空")
        }else{
            $('#tips').text("")
            $.ajax({
           
                type: "POST",
                dataType: "json",
                url: url + "/page/selectByArea" ,//url
                data: {
                    start:start,
                    end:end
                },
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 1) {
                       
                        console.log(result.data.firstPrice)
                        console.log(result.data.continuation)
                        $('#first').text(result.data.firstPrice);
                        $('#finally').text(result.data.continuation);
                    }else if(result.code == 2){
                        $('#tips').text("无效的地址")
                        $('#first').text("-");
                        $('#finally').text("-");
                    }
                    
                },
                error : function() {
                    layer.msg("网络繁忙,请稍后再试");
                }
            });
        }
    })

    $('#end').blur(function(){
        let start = $('#start').val();
        let end = $('#end').val();
        if(start=="" || end==""){
            
            $('#tips').text("查询地址不能为空")
        }else{
            $('#tips').text("")
            $.ajax({
           
                type: "POST",
                dataType: "json",
                url: url + "/page/selectByArea" ,//url
                data: {
                    start:start,
                    end:end
                },
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 1) {
                       
                        console.log(result.data.firstPrice)
                        console.log(result.data.continuation)
                        $('#first').text(result.data.firstPrice);
                        $('#finally').text(result.data.continuation);
                    }else if(result.code == 2){
                        $('#tips').text("无效的地址")
                        $('#first').text("-");
                        $('#finally').text("-");
                    }
                    
                },
                error : function() {
                    layer.msg("网络繁忙,请稍后再试");
                }
            });

        }
    })


    $(".delivery").click(function(){
        $(location).attr('href', 'booking_delivery.html');
    })

    $(function () {

        $("#sendPhone").blur(function () {

            let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
            let sendPhone = $.trim($('#sendPhone').val());
            if (sendPhone == "") {
                // layer.msg("请输入有效的手机号码");
                $('#sendPhone').css({border: "solid 1px red"});
                $('#send-phone-p').html("手机号不能为空");
            } else {
                if (!phoneReg.test(sendPhone)) {
                    $('#sendPhone').css({border: "solid 1px blue"});
                    $('#send-phone-p').html("");
                    $('#sendPhone').css({border: "solid 1px red"});
                    $('#send-phone-p').html("请输入正确的手机号");
                } else {
                    $('#sendPhone').css({border: "solid 1px #67C23A"});
                    $('#send-phone-p').html("");
                }
            }
        });


        $("#sendName").blur(function () {
            let sendName = $.trim($('#sendName').val());
            if (sendName == "") {
                $('#sendName').css({border: "solid 1px red"});
                $('#send-name-p').html("寄件人姓名不能为空");

            } else {
                $('#sendName').css({border: "solid 1px #67C23A"});
                $('#send-name-p').html("");


            }
        });

       

        $("#sendAddress").blur(function () {
            let sendAddress = $.trim($('#sendAddress').val());
            if (sendAddress == "") {
                $('#sendAddress').css({border: "solid 1px red"});
                $('#send-address-p').html("请输入详细地址");

            } else {
                $('#sendAddress').css({border: "solid 1px #67C23A"});
                $('#send-address-p').html("");


            }
        });


    });
})